import { createStore } from 'vuex'

export default createStore({
  state: {
    token: null
  },
  getters: {
    getToken(state){
      return state.token || localStorage.getItem('token') || null;
    }
  },
  mutations: {
    SET_TOKEN(state, token) { 
      localStorage.setItem('token',token);
      state.token = token; 
    },
    REMOVE_TOKEN(state){
      state.token = null;
      removeToken('token');
    },
    CLEAR_TOKEN(state) {
      state.token = null;
    
    }
  },
  actions: {
    setToken({ commit }, token) {
      commit('SET_TOKEN', token);
    },

    clearToken({ commit }) {
      commit('CLEAR_TOKEN');
    }
  },
  modules: {
  }
})
